/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Controller.ReservationController;
import java.beans.PropertyChangeEvent;
import javax.swing.JPanel;
import javax.swing.JTable;
import java.util.Date;
import Model.Agenda;

/**
 *
 * @author fokasu
 */
public class ChoisirChambre extends AbstractViewPanel {
    private CreerReservation _currentReservation = null;
    private ReservationController _controller = null;
    private Date _dteDebut;
    private Date _dteFin;
    private String _nomCat;
    /**
     * Creates new form ChoisirChambre
     */
    public ChoisirChambre(CreerReservation reservationView, ReservationController reservationController, Date dteDebut, Date dteFin) {
        _currentReservation = reservationView;
        _controller = reservationController;
        _dteDebut = dteDebut;
        _dteFin = dteFin;
        
        initComponents();
        
        populerTable(Agenda.getInstance().AfficherCategorie(_dteDebut, _dteFin));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tblChambreLibre = new javax.swing.JTable();
        btnOK = new javax.swing.JButton();
        btnAnuller = new javax.swing.JButton();

        tblChambreLibre.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Catégorie", "Nb de chambres libre"
            }
        ));
        jScrollPane1.setViewportView(tblChambreLibre);

        btnOK.setText("OK");
        btnOK.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnOKMouseClicked(evt);
            }
        });

        btnAnuller.setText("Anuller");
        btnAnuller.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnAnullerMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnOK, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnAnuller))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAnuller)
                    .addComponent(btnOK))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnOKMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnOKMouseClicked
        _currentReservation.changeCategorie(tblChambreLibre.getSelectedRow());
        this.getTopLevelAncestor().setVisible(false);
    }//GEN-LAST:event_btnOKMouseClicked

    private void btnAnullerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnAnullerMouseClicked
        this.getTopLevelAncestor().setVisible(false);
    }//GEN-LAST:event_btnAnullerMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAnuller;
    private javax.swing.JButton btnOK;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblChambreLibre;
    // End of variables declaration//GEN-END:variables

     private void populerTable(String[][] lstCategorie){
        
        String[] celNames;
        
        celNames = new String[2];
        celNames[0] = "Categorie";
        celNames[1] = "Nb Chambre";
        
        JTable jtbl = new JTable(lstCategorie, celNames);
        
        this.tblChambreLibre.setModel(jtbl.getModel());        
    }

    @Override
    public void modelPropertyChange(PropertyChangeEvent evt) {
        
        switch(evt.getPropertyName()){
            case ReservationController.CLIENT_PROPERTY:
                this.getTopLevelAncestor().setVisible(false);
                break;
        }
    }
}
